#! /usr/bin/awk -f

# pb.awk
# define VER=0.3
# prepared by: Luciano V. 

# This file facilitates conversion tool to take in .csv list of all 
# phone numbers and returns new file with full blown user matrix 
# ready to import into Cisco Unified Communications Manager

#################################
# HOW TO
#################################
# To use it, chmod this script to executable
# prepare input file in csv format as "user , nickname" per each line
# do: ./pb.awk input_file.csv > output_file.csv 
# you will get a new output_file.csv with following fields in lines formatted
# User ID, User Domain, Contact ID, Contact Domain, Nickname, Group Name
# change parameters in "BEGIN" to match your own 


BEGIN {
	RS="\n"
	FS=","
	i=0;
	names[0]=""				# User ID - array holding all user names from csv
	udom="domain.com"	# User Domain - set your own
	cid=""					   # Contact ID - never used, this one is dynamic, replicated from User ID
	cdom="domain.com"	 # Contact domain - prolly the same as user domain, set your own if not
	nicks[0]=""				# Contact nickname - if existed earlier, array will hold nicks from csv
	gname="group"			# Group name - prolly the same for all users, make your own
}
{  
		gsub(/ /,"",$1)
		names[i]=$1
		nicks[i]=$2
		i++
}
END {

	for (x=0; x<i; x++) {
		for (y=0; y<i; y++) { 
			if (y != x) {
				print names[x] "," udom "," names[y] "," cdom "," nicks[y] "," gname
			}
		}
	}
}

